﻿/* mvcForum
 * Copyright (C) 2010-2011 Steen F. Tøttrup
 * http://mvcforum.org/
 */

using System;
using System.ComponentModel.DataAnnotations;

namespace mvcForum.Core {

	/// <summary>
	/// This class represent a reported post.
	/// </summary>
	public class PostReport {
		public PostReport() { }
		//public PostReport(Post post, String reason) : this(post, reason, null, false) { }
		public PostReport(Post post, String reason, ForumUser reportedBy) : this(post, reason, reportedBy, false) { }
		public PostReport(Post post, String reason, ForumUser reportedBy, Boolean feedback) {
			this.Post = post;
			this.Reason = reason;
			this.Timestamp = DateTime.UtcNow;
			this.Resolved = false;
			if (reportedBy != null) {
				this.ReportedBy = reportedBy;
			}
			this.Feedback = feedback;
		}

		//        #region Methods
		//        /// <summary>
		//        /// Method for resolving the issue raised in the report.
		//        /// </summary>
		//        /// <param name="user">The user resolving the issue.</param>
		//        public void Resolve(ForumUser user) {
		//            this.Resolved = true;
		//            this.ResolvedBy = user.Id;
		//            this.ResolvedTimestamp = DateTime.UtcNow;
		//        }
		//        #endregion

		#region Properties
		public Int32 Id { get; set; }
		/// <summary>
		/// The post in question.
		/// </summary>
		[Required]
		public Int32 PostId { get; set; }
		public virtual Post Post { get; set; }
		private DateTime timestamp;
		/// <summary>
		/// Timestamp of when the post was reported.
		/// </summary>
		[Required]
		public DateTime Timestamp {
			get {
				return this.timestamp;
			}
			set {
				this.timestamp = value.Handle();
			}
		}
		/// <summary>
		/// The reason given for reporting the post.
		/// </summary>
		[Required]
		[StringLength(Constants.FieldLengths.ReportReason)]
		public String Reason { get; set; }
		/// <summary>
		/// The user that reported the post.
		/// </summary>
		[Required]
		public Int32 ReportedById { get; set; }
		public virtual ForumUser ReportedBy { get; set; }
		/// <summary>
		/// Boolean indicating whether or not the reporter would like to be informed when the report has been resolved.
		/// </summary>
		[Required]
		public Boolean Feedback { get; set; }
		[Required]
		public Boolean Resolved { get; set; }
		/// <summary>
		/// When the issue has been resolved, the resolving user.
		/// </summary>
		public Int32? ResolvedById { get; set; }
		public virtual ForumUser ResolvedBy { get; set; }
		private DateTime? resolvedTimestamp;
		/// <summary>
		/// When the issue has been resolved, the timestamp of when the issue was resolved.
		/// </summary>
		public DateTime? ResolvedTimestamp {
			get {
				return this.resolvedTimestamp;
			}
			set {
				this.resolvedTimestamp = value.Handle();
			}
		}
		#endregion
	}
}